$(function(){
  const token = localStorage.getItem('Atoken') || ''
  // console.log('token', token)

  

  if(token === '') {
    layer.msg('请先登录')
  return $('.slinks').html(`<a href="login.html"><i class="fa fa-hand-o-right"></i>&nbsp;登录</a> |
  <a href="reg.html"><i class="fa fa-registered"></i>&nbsp;注册</a>`)
  } else{
    getUserInfo()
  }

  
  // 点击退出登录
  $('.slinks').on('click', '.fa', function(){
    location.href = './login.html'
    localStorage.removeItem('token')
  })


})


function getUserInfo(){
  $.ajax({
    method: 'POST',
    url: '/user/getUserInfo',
    success: function(res) {
      console.log(res);
      const user = res.data.userInfo.username || res.data.userInfo.mobile
      $('.slinks').html(`<a data-v-697ed175="" href="#/user" class="router-link-exact-active router-link-active" aria-current="page">
      <i data-v-697ed175="" class="fa fa-user"></i>&nbsp; 您好${ user }，</a>
      <a data-v-697ed175="" class="fa fa-sign-out"></a>
      `)
     $('.user-info .text h3').html(`昵称 ${ user }<span><b>个性宣言</b>:${res.data.userInfo.notes ? res.data.userInfo.notes : '走自己的路，让人说去吧'}</span>`)
     $('.user-info .text p').html(` 性别：${res.data.userInfo.sex ? '女' : '男'}<span> |</span>
     手机号：${res.data.userInfo.mobile} <span>|</span>
     出生年月：${res.data.userInfo.birthday}`)
     $('.container .img').attr('src',`http://124.223.14.236:8060/${res.data.userInfo.icon}`)
    }
  })
}